package com.anjubao.parking.municipal.parkinglot.service;

import com.anjubao.parking.municipal.parkinglot.dto.ParkingLotMonitorGuidanceResDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingLotMonitorResDto;
import com.anjubao.parking.municipal.parkinglot.mapper.ParkingLotDeviceStatusMapper;
import com.anjubao.parking.municipal.parkinglot.model.ParkingLotDeviceStatus;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 设备运行状况统计service
 * @author anjubao
 */
@Service
public class ParkingLotDeviceMonitorService extends ServiceImpl<ParkingLotDeviceStatusMapper, ParkingLotDeviceStatus> {

    @Autowired
    private ParkingLotDeviceStatusMapper parkingLotDeviceStatusMapper;

    /**
     * 统计设备运行状况
     * @param cityId
     * @return
     */
    public List<ParkingLotMonitorResDto> selectDevices(Integer cityId) {
        //统计设备运行状况
        List<ParkingLotMonitorResDto> parkingLotDeviceResDtos=parkingLotDeviceStatusMapper.selectDevices(cityId);
        //循环获取所有设备得在线离线数量
        int onlineTotal=0;
        int offlineTotal=0;
        for (ParkingLotMonitorResDto parkingLotDeviceResDto : parkingLotDeviceResDtos) {
            //将各个类型设备数据封装到map中
            onlineTotal+=parkingLotDeviceResDto.getOnline();
            offlineTotal+=parkingLotDeviceResDto.getOffline();
        }
        //新建一条记录保存设备总在/离线数
        ParkingLotMonitorResDto parkingLotDeviceResDto=new ParkingLotMonitorResDto();
        parkingLotDeviceResDto.setDeviceType(0);
        parkingLotDeviceResDto.setOnline(onlineTotal);
        parkingLotDeviceResDto.setOffline(offlineTotal);
        parkingLotDeviceResDtos.add(parkingLotDeviceResDto);
        return parkingLotDeviceResDtos;
    }

    /**
     * 诱导屏运行状况统计
     * @param cityId
     * @return
     */
    public List<ParkingLotMonitorGuidanceResDto> selectGuidanceScreen(Integer cityId) {
        return parkingLotDeviceStatusMapper.selectGuidanceScreen(cityId);
    }
}
